package es.mgil.linternas;

import java.util.Random;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;

public class LinternaAleatoria extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(new LinternaAleatoriaRelativeLayout(this));
	}

	private class LinternaAleatoriaRelativeLayout extends RelativeLayout {
		private Random random = new Random();

		public LinternaAleatoriaRelativeLayout(Context context) {
			super(context);
			this.setBackgroundColor(0xffffffff);
		}

		@Override
		protected void onDraw(Canvas canvas) {
			canvas.drawRGB(random.nextInt(256), random.nextInt(256),
					random.nextInt(256));
			try {
				Thread.sleep(200);
			} catch (InterruptedException e) {
			} finally {
				invalidate();
			}
		}
	}
}
